<?
include_once('../conn.php');
include_once('func.php');
include("../user_check.php") ;
if(isset($_GET[successful])){
	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><div style="border:#999 1px solid; padding:5px; text-align:center; font-size:16px;">'.PAY_SUCCESSFUL_PAYMENT.'</div>';
	exit;
	}


///
		$order = $db->select("SELECT * FROM `".tablepre."order` where oid = $_GET[oid]");
	$order_item = $db->select("SELECT amount,price FROM `".tablepre."order_item` where oid = $_GET[oid]");
	for($i=0;$i<count($order_item);$i++){
		$order_item_count .= $order_item[$i][0].',';
		$order_price_count .= $order_item[$i][1].',';
		}
		
if(isset($_GET[payment])){
			$order = $db->select("SELECT * FROM `".tablepre."order` where oid = $_GET[oid]");
	$order_item = $db->select("SELECT amount,price FROM `".tablepre."order_item` where oid = $_GET[oid]");
	for($i=0;$i<count($order_item);$i++){
		$order_item_count .= $order_item[$i][0].',';
		$order_price_count .= $order_item[$i][1].',';
		}
		////
	if(array_sum(explode(',',$order_price_count))>mamber($con1=$checkmember[0][2],$con2=7)){
		echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><div style="border:#999 1px solid; padding:5px; text-align:center; font-size:16px;">'.ORDER_DEPOSIT_INSUFFICIENT.'</div>';
		exit('<script>alert("'.ORDER_DEPOSIT_INSUFFICIENT.'");</script>
		');
		}
	$db->UPDATE("UPDATE `".tablepre."order` SET `paid`='1' WHERE (`oid`='$_GET[oid]')");
	$db->UPDATE("UPDATE `".tablepre."user` SET advance = concat(advance - ".array_sum(explode(',',$order_price_count)).") , score = concat(score + '".$order[0][17]."') , salesvolume = concat(salesvolume + '".$order[0][18]."')  WHERE (`uid`='".$checkmember[0][2]."')");
	exit('<script>location="?successful";</script>');
		// echo PAY_SUCCESSFUL_PAYMENT;
		 exit;}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>order view</title>
<style type="text/css">
body,td,th {
	font-size: 12px;
	color: #333;
}
</style>
</head>

<body>

<table width="500" border="0" cellspacing="2" cellpadding="2">
      <tr style="border-bottom:#666 1px solid;">
        <td colspan="2"><? echo PAY_NOTICE1.parameters($con1=23).PAY_NOTICE2;?></td>
      </tr>
      <tr>
        <td width="125" align="right"><? echo ORDER_SN;?>：</td>
        <td width="361"><? echo $order[0][4];?></td>
      </tr>
      <tr>
        <td align="right"><? echo ORDER_TOTAL;?>：</td>
        <td><? echo unit(array_sum(explode(',',$order_price_count)));?></td>
      </tr>
      <tr>
        <td align="right"><? echo PAY_ITEM_QUANTITY;?>：</td>
        <td><? echo array_sum(explode(',',$order_item_count));?></td>
      </tr>
      <tr>
        <td align="right"><? echo PAY_PAYMENT_METHOD;?>：</td>
        <td><? echo $order[0][14];?></td>
      </tr>
      <tr>
        <td align="right"><? echo MEMBER_DEPOSIT;?>：</td>
        <td><? echo unit(mamber($con1=$checkmember[0][2],$con2=7));?></td>
      </tr>
      <tr>
        <td align="right"></td>
        <td>
		<script>
        function p_l(){
			parent.location.href = "../user_payment.php";
			}
        </script>
		<? if(array_sum(explode(',',$order_price_count))>mamber($con1=$checkmember[0][2],$con2=7)){echo ORDER_DEPOSIT_INSUFFICIENT.'<br><input type="button" onclick="p_l()" value="'.PAY_RECHARGE_NOW.'" />';
		//<input type="submit" value="'.PAY_RECHARGE_NOW.'" onClick="location=\'user_payment.php\'"/>
		}else{
			echo '<input type="submit" value="'.PAY_PAYMENT.'" onClick="location=\'?payment&oid='.$_GET[oid].'\'"/>';
			//echo '<a href="user_order.php?payment&oid='.$_GET[oid].'">'.PAY_PAYMENT.'</a>';
			}?></td>
      </tr>
      <tr>
        <td align="right">&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
    </table>

</body>
</html>